<script>
    window.nav = new Vue({
        data: {
            activeIndex: 'home',
            context: '${context?default("")}',
            tip: {
                show: function (msg) {
                    if (msg) {
                        this.$indicator.open(msg);
                    } else {
                        this.$indicator.open();
                    }
                },
                close: function () {
                    this.$indicator.close();
                }
            },
        },
        methods: {
            i: function (message, callback) {
                this.$toast({
                    message: message,
                    position: 'middle',
                    duration: 3000
                });
                setTimeout(callback, 3000)
            },
            alert: function (message, callback) {
                this.$messageBox.alert(message, "").then(callback);
            },
            confirm: function (message, callback) {
                this.$messageBox.confirm(message, "").then(callback);
            }
        }
    });

    Vue.prototype.$action = 'go';
    Vue.prototype.$isSubmit = false;
    Vue.mixin({
        methods: {
            $push: function (param) {
                Vue.prototype.$action = 'go';
                if (typeof param === 'string') {
                    param = {
                        name: param
                    };
                }
                this.$router.push(param);
            },
            $pop: function () {
                Vue.prototype.$action = 'back';
                // if (typeof (this.$router) === 'undefined') {//客户端使用时偶会出现undefined错误
                //     window.history.back();
                //     this.$destroy();
                // } else {
                this.$router.go(-1);
                this.$destroy();
                // }
            },
            $replace: function (param) {
                Vue.prototype.$action = 'go';
                if (typeof param === 'string') {
                    param = {
                        name: param
                    };
                }
                this.$router.replace(param);
            },
            $home: function () {
                Vue.prototype.$action = 'back';
                this.$router.push("nav")
                this.$destroy()
            },
            $showLoading: function () {
                this.$toast.loading({
                    duration: 0,
                    forbidClick: true,
                    message: '请稍等...'
                });
                Vue.prototype.$isSubmit = true
            },
            $closeLoading: function () {
                this.$toast.clear();
                Vue.prototype.$isSubmit = false
            },
            $showMessage: function (msg, fn) {
                this.$toast({
                    duration: 1000,
                    message: msg
                });
                if (typeof fn === 'function') {
                    setTimeout(function () {
                        fn();
                    }, 1000)
                }
            },
        },
        activated: function () {
        },
        filters: {
            notNull: function (val) {
                if (val === null) {
                    return "";
                }
            },
        }
    });

    Vue.component('form-area', {
        data: function () {
            return {
                showValue: ''
            }
        },
        props: {
            'label': {
                type: String,
                default: ''
            },
            'required': {
                type: Boolean,
                default: false
            },
            'readonly': {
                type: Boolean,
                default: false
            },
            'value': {
                type: String,
                default: ''
            }
        },
        methods: {
            onChange: function (value) {
                this.$emit('input', value);
            }
        },
        template: '' +
        '<van-field' +
        '  :value="value"' +
        '  :required="required"' +
        '  clearable' +
        '  :readonly="readonly"' +
        '  type="textarea"' +
        '  row="3"' +
        '  :label="label"' +
        '  @input="onChange"' +
        '  :placeholder="\'请输入\'"/>'
    });

</script>